﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;

namespace zielonka.co.uk.extensions.system
{
    /*
        Color foreColor = someBackColor.GetForegroundColor();
     */

    public static partial class ColorExtensions
    {
        public static Color GetForegroundColor(this Color input)
        {
            // Math taken from one of the replies to
            // http://stackoverflow.com/questions/2241447/make-foregroundcolor-black-or-white-depending-on-background
            if (Math.Sqrt(input.R * input.R * .241 + input.G * input.G * .691 + input.B * input.B * .068) > 128)
                return Color.Black;
            else
                return Color.White;
        }

    }
}
